﻿// https://mp.weixin.qq.com/s?__biz=MzUxNjY5NTYxNA==&mid=2247489200&idx=2&sn=ec0648614a6ffda417e997632eac185f&scene=21#wechat_redirect
// https://leetcode-cn.com/problems/intersection-of-two-arrays/

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>

using namespace std;

// struct ListNode {
//     int val;
//     ListNode *next;
//     ListNode() : val(0), next(nullptr) {}
//     ListNode(int x) : val(x), next(nullptr) {}
//     ListNode(int x, ListNode *next) : val(x), next(next) {}
// };

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        unordered_set<int> num_set, rep_set;
        vector<int> result;

        for (int i = 0; i < nums1.size(); i++) {
            if (num_set.find(nums1[i]) == num_set.end())
                num_set.insert(nums1[i]);
        }

        for (int i = 0; i < nums2.size(); i++) {
            if (num_set.find(nums2[i]) != num_set.end())
                if (rep_set.find(nums2[i]) == rep_set.end()) {
                    result.push_back(nums2[i]);
                    rep_set.insert(nums2[i]);
                }
                
        }
        return result;
    }
};

int main() {
    Solution obj = Solution();
}